package Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Service.Servlet;
import vo.Cjb;


@WebServlet("/chengji")
public class ChengjiServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Servlet a = new Servlet();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		Integer user_id = Integer.parseInt(request.getParameter("xs_id"));
		Integer kc_id = Integer.parseInt(request.getParameter("kc_id"));
		List<Cjb> list = a.find2();
		int i = -1;
		for(Cjb cjb: list){
			if(cjb.getUser_id() == user_id){
				i = 1;
				break;
			}
		}
		Integer cless_id = Integer.parseInt(request.getParameter("cless_id"));
		Integer achievement = Integer.parseInt(request.getParameter("cj"));
		Cjb str =new Cjb(user_id,kc_id,achievement);
		if(i == 1){
			a.update(str);
		}else{
			a.cjgl(str);			
		}
		response.sendRedirect("student_cj?bjid="+cless_id+"&kcid="+kc_id);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
